#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2021 wanghch <wanghch@wanghch-pc>
#
# Distributed under terms of the MIT license.

"""

"""
import pandas as pd
from sklearn.model_selection import train_test_split
import tensorflow as tf
import os
from tensorflow.keras.layers import *

FEATURES = ['rsi_6', 'rsi_12', 'rsi_24', 'stoch_k', 'stoch_d', 'stoch_j', 'BBP', 'BLOW_HIGH', 'macd', 'macdsignal', 'macdhist', 'SMA_DIFF_5', 'SMA_DIFF_13', 'SMA_DIFF_21', 'SMA_DIFF_34', 'SMA_DIFF_55', 'SMA_DIFF_89', 'SMA_DIFF_144', 'SMA_DIFF_233', 'SMA_DIFF_377', 'SMA_5_13_DIFF', 'SMA_5_21_DIFF', 'SMA_5_34_DIFF', 'SMA_5_55_DIFF', 'SMA_5_89_DIFF', 'SMA_5_144_DIFF', 'SMA_5_233_DIFF', 'SMA_5_377_DIFF', 'SMA_13_21_DIFF', 'SMA_13_34_DIFF', 'SMA_13_55_DIFF', 'SMA_13_89_DIFF', 'SMA_13_144_DIFF', 'SMA_13_233_DIFF', 'SMA_13_377_DIFF', 'SMA_21_34_DIFF', 'SMA_21_55_DIFF', 'SMA_21_89_DIFF', 'SMA_21_144_DIFF', 'SMA_21_233_DIFF', 'SMA_21_377_DIFF', 'SMA_34_55_DIFF', 'SMA_34_89_DIFF', 'SMA_34_144_DIFF', 'SMA_34_233_DIFF', 'SMA_34_377_DIFF', 'SMA_55_89_DIFF', 'SMA_55_144_DIFF', 'SMA_55_233_DIFF', 'SMA_55_377_DIFF', 'SMA_89_144_DIFF', 'SMA_89_233_DIFF', 'SMA_89_377_DIFF', 'SMA_144_233_DIFF', 'SMA_144_377_DIFF', 'SMA_233_377_DIFF', 'peTTM_377_SMA_diff', 'pbMRQ_377_SMA_diff', 'psTTM_377_SMA_diff', 'pcfNcfTTM_377_SMA_diff', 'VOL_SMA_DIFF_5', 'VOL_SMA_DIFF_13', 'VOL_SMA_DIFF_21', 'VOL_SMA_DIFF_34', 'VOL_SMA_DIFF_55', 'VOL_SMA_DIFF_89', 'VOL_SMA_DIFF_144', 'VOL_SMA_DIFF_233', 'VOL_SMA_DIFF_377']

df = pd.read_csv('data.txt')
df['dt'] = pd.to_datetime(df.date)

print(df.shape)
X = df[df.date < '2018-01-01']
X2 = df[df.date >= '2018-01-01']
print(X.shape)
print(X2.shape)

X_train, Y_train = X.loc[:, FEATURES], X.loc[:, 'target']
X_test, Y_test = X2.loc[:, FEATURES], X2.loc[:, 'target']


#X_train, X_test, Y_train, Y_test = train_test_split(X,Y,test_size = 0.2,random_state = 22)
#
#
layers = []
#for i in [128,128, 64,32]:
for i in [128,128,128,64, 64,32]:
    layers.append(tf.keras.layers.Dense(i, activation='relu'))
layers.append(tf.keras.layers.Dense(1, activation='sigmoid'))
model = tf.keras.Sequential(layers)
model.compile(
    loss='binary_crossentropy',
    optimizer='adam',
    metrics=['accuracy'])

model_dir = "peak_model2_2"
callbacks = []
log_dir = "train_logs/"
tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir=log_dir, histogram_freq=1)
callbacks.append(tensorboard_callback)

model.fit(X_train, Y_train, epochs = 5, callbacks=callbacks)
model.save(model_dir)
model.evaluate(X_test, Y_test)
